home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Programming / fpc / amigaunits / workbench.pas < prev   
Pascal/Delphi Source File  |  1998-09-22  |  10KB  |  336 lines

  1. {
  2.     This file is part of the Free Pascal run time library.
  3.  
  4.     A file in Amiga system run time library.
  5.     Copyright (c) 1998 by Nils Sjoholm
  6.     member of the Amiga RTL development team.
  7.  
  8.     See the file COPYING.FPC, included in this distribution,
  9.     for details about the copyright.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14.  
  15.  **********************************************************************}
  16.  
  17. unit workbench;
  18.  
  19. INTERFACE
  20.  
  21. uses exec,amigados,utility, intuition;
  22.  
  23.  
  24. Type
  25.  
  26.     pWBArg = ^tWBArg;
  27.     tWBArg = record
  28.         wa_Lock         : Pointer;      { a lock descriptor }
  29.         wa_Name         : STRPTR;       { a string relative to that lock }
  30.     end;
  31.  
  32.     WBArgList = Array [1..100] of tWBArg; { Only 1..smNumArgs are valid }
  33.     pWBArgList = ^WBArgList;
  34.  
  35.  
  36.     pWBStartup = ^tWBStartup;
  37.     tWBStartup = record
  38.         sm_Message      : tMessage;      { a standard message structure }
  39.         sm_Process      : pMsgPort;   { the process descriptor for you }
  40.         sm_Segment      : BPTR;         { a descriptor for your code }
  41.         sm_NumArgs      : Longint;      { the number of elements in ArgList }
  42.         sm_ToolWindow   : STRPTR;       { description of window }
  43.         sm_ArgList      : pWBArgList; { the arguments themselves }
  44.     end;
  45.  
  46.  
  47. Const
  48.  
  49.     WBDISK              = 1;
  50.     WBDRAWER            = 2;
  51.     WBTOOL              = 3;
  52.     WBPROJECT           = 4;
  53.     WBGARBAGE           = 5;
  54.     WBDEVICE            = 6;
  55.     WBKICK              = 7;
  56.     WBAPPICON           = 8;
  57.  
  58. Type
  59.  
  60.     pOldDrawerData = ^tOldDrawerData;
  61.     tOldDrawerData = record
  62.         dd_NewWindow    : tNewWindow;    { args to open window }
  63.         dd_CurrentX     : Longint;      { current x coordinate of origin }
  64.         dd_CurrentY     : Longint;      { current y coordinate of origin }
  65.     end;
  66.  
  67. Const
  68.  
  69. { the amount of DrawerData actually written to disk }
  70.  
  71.     OLDDRAWERDATAFILESIZE  = 56;  { sizeof(OldDrawerData) }
  72.  
  73. Type
  74.     pDrawerData = ^tDrawerData;
  75.     tDrawerData = record
  76.         dd_NewWindow    : tNewWindow;    { args to open window }
  77.         dd_CurrentX     : Longint;      { current x coordinate of origin }
  78.         dd_CurrentY     : Longint;      { current y coordinate of origin }
  79.         dd_Flags        : Longint;      { flags for drawer }
  80.         dd_ViewModes    : Word;        { view mode for drawer }
  81.     end;
  82.  
  83. Const
  84.  
  85. { the amount of DrawerData actually written to disk }
  86.  
  87.     DRAWERDATAFILESIZE  = 62;  { sizeof(DrawerData) }
  88.  
  89.  
  90. Type
  91.  
  92.     pDiskObject = ^tDiskObject;
  93.     tDiskObject = record
  94.         do_Magic        : Word;        { a magic number at the start of the file }
  95.         do_Version      : Word;        { a version number, so we can change it }
  96.         do_Gadget       : tGadget;       { a copy of in core gadget }
  97.         do_Type         : Byte;
  98.         do_DefaultTool  : STRPTR;
  99.         do_ToolTypes    : Pointer;
  100.         do_CurrentX     : Pointer;
  101.         do_CurrentY     : Longint;
  102.         do_DrawerData   : pDrawerData;
  103.         do_ToolWindow   : STRPTR;       { only applies to tools }
  104.         do_StackSize    : Longint;      { only applies to tools }
  105.     end;
  106.  
  107. Const
  108.  
  109.     WB_DISKMAGIC        = $e310;        { a magic number, not easily impersonated }
  110.     WB_DISKVERSION      = 1;            { our current version number }
  111.     WB_DISKREVISION     = 1;            { our current revision number }
  112.   {I only use the lower 8 bits of Gadget.UserData for the revision # }
  113.     WB_DISKREVISIONMASK = 255;
  114. Type
  115.     pFreeList = ^tFreeList;
  116.     tFreeList = record
  117.         fl_NumFree      : Integer;
  118.         fl_MemList      : tList;
  119.     end;
  120.  
  121. Const
  122.  
  123. { each message that comes into the WorkBenchPort must have a type field
  124.  * in the preceeding short.  These are the defines for this type
  125.  }
  126.  
  127.     MTYPE_PSTD          = 1;    { a "standard Potion" message }
  128.     MTYPE_TOOLEXIT      = 2;    { exit message from our tools }
  129.     MTYPE_DISKCHANGE    = 3;    { dos telling us of a disk change }
  130.     MTYPE_TIMER         = 4;    { we got a timer tick }
  131.     MTYPE_CLOSEDOWN     = 5;    { <unimplemented> }
  132.     MTYPE_IOPROC        = 6;    { <unimplemented> }
  133.     MTYPE_APPWINDOW     = 7;    {     msg from an app window }
  134.     MTYPE_APPICON       = 8;    {     msg from an app icon }
  135.     MTYPE_APPMENUITEM   = 9;    {     msg from an app menuitem }
  136.     MTYPE_COPYEXIT      = 10;   {     exit msg from copy process }
  137.     MTYPE_ICONPUT       = 11;   {     msg from PutDiskObject in icon.library }
  138.  
  139.  
  140. { workbench does different complement modes for its gadgets.
  141.  * It supports separate images, complement mode, and backfill mode.
  142.  * The first two are identical to intuitions GADGIMAGE and GADGHCOMP.
  143.  * backfill is similar to GADGHCOMP, but the region outside of the
  144.  * image (which normally would be color three when complemented)
  145.  * is flood-filled to color zero.
  146.  }
  147.  
  148.     GFLG_GADGBACKFILL   = $0001;
  149.     GADGBACKFILL        = $0001;   { an old synonym }
  150.  
  151. { if an icon does not really live anywhere, set its current position
  152.  * to here
  153.  }
  154.  
  155.     NO_ICON_POSITION    = $80000000;
  156.  
  157. {    If you find am_Version >= AM_VERSION, you know this structure has
  158.  * at least the fields defined in this version of the include file
  159.  }
  160.  AM_VERSION   =   1;
  161.  
  162. Type
  163.    pAppMessage = ^tAppMessage;
  164.    tAppMessage = record
  165.     am_Message       : tMessage;            {    standard message structure }
  166.     am_Type          : Word;              {    message type }
  167.     am_UserData      : ULONG;            {    application specific }
  168.     am_ID            : ULONG;            {    application definable ID }
  169.     am_NumArgs       : ULONG;            {    # of elements in arglist }
  170.     am_ArgList       : pWBArgList;       {    the arguements themselves }
  171.     am_Version       : Word;              {    will be AM_VERSION }
  172.     am_Class         : Word;              {    message class }
  173.     am_MouseX        : Integer;              {    mouse x position of event }
  174.     am_MouseY        : Integer;              {    mouse y position of event }
  175.     am_Seconds       : ULONG;            {    current system clock time }
  176.     am_Micros        : ULONG;            {    current system clock time }
  177.     am_Reserved      : Array[0..7] of ULONG;       {    avoid recompilation }
  178.    END;
  179.  
  180. {* types of app messages *}
  181. const
  182.     AMTYPE_APPWINDOW   = 7;    {* app window message    *}
  183.     AMTYPE_APPICON     = 8;    {* app icon message  *}
  184.     AMTYPE_APPMENUITEM = 9;    {* app menu item message *}
  185.  
  186. {
  187.  * The following structures are private.  These are just stub
  188.  * structures for code compatibility...
  189.  }
  190. type
  191.  
  192.  tAppWindow = record
  193.    aw_PRIVATE : Pointer;
  194.  END;
  195.  pAppWindow = ^tAppWindow;
  196.  
  197.  tAppIcon = record
  198.    ai_PRIVATE : Pointer;
  199.  END;
  200.  pAppIcon = ^tAppIcon;
  201.  
  202.  tAppMenuItem = record
  203.    ami_PRIVATE : Pointer;
  204.  END;
  205.  pAppMenuItem = ^tAppMenuItem;
  206.  
  207.  
  208. CONST
  209.     WORKBENCHNAME : PChar  = 'workbench.library';
  210.  
  211. VAR
  212.     WorkbenchBase : pLibrary;
  213.  
  214. FUNCTION AddAppIconA(id : ULONG; userdata : ULONG; text : pCHAR; msgport : pMsgPort; lock : pFileLock; diskobj : pDiskObject; taglist : pTagItem) : pAppIcon;
  215. FUNCTION AddAppMenuItemA(id : ULONG; userdata : ULONG; text : pCHAR; msgport : pMsgPort; taglist : pTagItem) : pAppMenuItem;
  216. FUNCTION AddAppWindowA(id : ULONG; userdata : ULONG; window : pWindow; msgport : pMsgPort; taglist : pTagItem) : pAppWindow;
  217. FUNCTION RemoveAppIcon(appIcon : pAppIcon) : BOOLEAN;
  218. FUNCTION RemoveAppMenuItem(appMenuItem : pAppMenuItem) : BOOLEAN;
  219. FUNCTION RemoveAppWindow(appWindow : pAppWindow) : BOOLEAN;
  220. PROCEDURE WBInfo(lock : BPTR; name : pCHAR; screen : pScreen);
  221.  
  222. IMPLEMENTATION
  223.  
  224. FUNCTION AddAppIconA(id : ULONG; userdata : ULONG; text : pCHAR; msgport : pMsgPort; lock : pFileLock; diskobj : pDiskObject; taglist : pTagItem) : pAppIcon;
  225. BEGIN
  226.   ASM
  227.     MOVE.L  A6,-(A7)
  228.     MOVE.L  id,D0
  229.     MOVE.L  userdata,D1
  230.     MOVEA.L text,A0
  231.     MOVEA.L msgport,A1
  232.     MOVEA.L lock,A2
  233.     MOVEA.L diskobj,A3
  234.     MOVEA.L taglist,A4
  235.     MOVEA.L WorkbenchBase,A6
  236.     JSR -060(A6)
  237.     MOVEA.L (A7)+,A6
  238.     MOVE.L  D0,@RESULT
  239.   END;
  240. END;
  241.  
  242. FUNCTION AddAppMenuItemA(id : ULONG; userdata : ULONG; text : pCHAR; msgport : pMsgPort; taglist : pTagItem) : pAppMenuItem;
  243. BEGIN
  244.   ASM
  245.     MOVE.L  A6,-(A7)
  246.     MOVE.L  id,D0
  247.     MOVE.L  userdata,D1
  248.     MOVEA.L text,A0
  249.     MOVEA.L msgport,A1
  250.     MOVEA.L taglist,A2
  251.     MOVEA.L WorkbenchBase,A6
  252.     JSR -072(A6)
  253.     MOVEA.L (A7)+,A6
  254.     MOVE.L  D0,@RESULT
  255.   END;
  256. END;
  257.  
  258. FUNCTION AddAppWindowA(id : ULONG; userdata : ULONG; window : pWindow; msgport : pMsgPort; taglist : pTagItem) : pAppWindow;
  259. BEGIN
  260.   ASM
  261.     MOVE.L  A6,-(A7)
  262.     MOVE.L  id,D0
  263.     MOVE.L  userdata,D1
  264.     MOVEA.L window,A0
  265.     MOVEA.L msgport,A1
  266.     MOVEA.L taglist,A2
  267.     MOVEA.L WorkbenchBase,A6
  268.     JSR -048(A6)
  269.     MOVEA.L (A7)+,A6
  270.     MOVE.L  D0,@RESULT
  271.   END;
  272. END;
  273.  
  274. FUNCTION RemoveAppIcon(appIcon : pAppIcon) : BOOLEAN;
  275. BEGIN
  276.   ASM
  277.     MOVE.L  A6,-(A7)
  278.     MOVEA.L appIcon,A0
  279.     MOVEA.L WorkbenchBase,A6
  280.     JSR -066(A6)
  281.     MOVEA.L (A7)+,A6
  282.     TST.W   D0
  283.     BEQ.B   @end
  284.     MOVEQ   #1,D0
  285.   @end: MOVE.B  D0,@RESULT
  286.   END;
  287. END;
  288.  
  289. FUNCTION RemoveAppMenuItem(appMenuItem : pAppMenuItem) : BOOLEAN;
  290. BEGIN
  291.   ASM
  292.     MOVE.L  A6,-(A7)
  293.     MOVEA.L appMenuItem,A0
  294.     MOVEA.L WorkbenchBase,A6
  295.     JSR -078(A6)
  296.     MOVEA.L (A7)+,A6
  297.     TST.W   D0
  298.     BEQ.B   @end
  299.     MOVEQ   #1,D0
  300.   @end: MOVE.B  D0,@RESULT
  301.   END;
  302. END;
  303.  
  304. FUNCTION RemoveAppWindow(appWindow : pAppWindow) : BOOLEAN;
  305. BEGIN
  306.   ASM
  307.     MOVE.L  A6,-(A7)
  308.     MOVEA.L appWindow,A0
  309.     MOVEA.L WorkbenchBase,A6
  310.     JSR -054(A6)
  311.     MOVEA.L (A7)+,A6
  312.     TST.W   D0
  313.     BEQ.B   @end
  314.     MOVEQ   #1,D0
  315.   @end: MOVE.B  D0,@RESULT
  316.   END;
  317. END;
  318.  
  319. PROCEDURE WBInfo(lock : BPTR; name : pCHAR; screen : pScreen);
  320. BEGIN
  321.   ASM
  322.     MOVE.L  A6,-(A7)
  323.     MOVEA.L lock,A0
  324.     MOVEA.L name,A1
  325.     MOVEA.L screen,A2
  326.     MOVEA.L WorkbenchBase,A6
  327.     JSR -090(A6)
  328.     MOVEA.L (A7)+,A6
  329.   END;
  330. END;
  331.  
  332. END. (* UNIT WB *)
  333.  
  334.  
  335.  
  336.